/*
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2023-09-30     FuLei       the first version
 */

#include <rtthread.h>
#include <rtdevice.h>
#include <board.h>
#include <at24cxx.h>
#include <SysInfo.h>
at24cxx_device_t  dev_at24cxx  = RT_NULL;
SysInfo_Struct SysInfo_Data, SysInfo_Datacopy;

void AT24Cxx_Init(void)
{
    dev_at24cxx = at24cxx_init( "i2c1", AT24CXX_ADDR);
}

void SystemInfo_Write(void)
{
    SysInfo_Data.para1 = 0x12;
    SysInfo_Data.para2 = 0x43;
    SysInfo_Data.para3 = 0x0818;
    SysInfo_Data.para4 = 0x22384296;

    at24cxx_write( dev_at24cxx, 0x01, (rt_uint8_t*)(&SysInfo_Data) , sizeof(SysInfo_Data) );
}
MSH_CMD_EXPORT(SystemInfo_Write, at24cxx eeprom infor write);

void SystemInfo_Read(void)
{
    at24cxx_read( dev_at24cxx, 0x01, (rt_uint8_t*)(&SysInfo_Datacopy) , sizeof(SysInfo_Data) );
    rt_kprintf("read para 1: %02x\n", SysInfo_Datacopy.para1 );
    rt_kprintf("read para 2: %02x\n", SysInfo_Datacopy.para2 );
    rt_kprintf("read para 3: %04x\n", SysInfo_Datacopy.para3 );
    rt_kprintf("read para 4: %08x\n", SysInfo_Datacopy.para4 );
}
MSH_CMD_EXPORT(SystemInfo_Read, at24cxx eeprom infor read);





//    at24cxx_device_t  dev_at24cxx = at24cxx_init( "i2c1", AT24CXX_ADDR);
//
//    at24cxx_write( dev_at24cxx, 0x01,data_w , 4);
//    rt_thread_mdelay(1000);
//    at24cxx_read(  dev_at24cxx, 0x01,data_r , 4);
//
//    rt_kprintf("read addr 1: %02x\n", data_r[0] );
//    rt_kprintf("read addr 2: %02x\n", data_r[1] );
//    rt_kprintf("read addr 3: %02x\n", data_r[2] );
//    rt_kprintf("read addr 4: %02x\n", data_r[3] );
